package edu.cmu.vlis.datamining.SimilarityFeatures;

import java.util.HashSet;
import java.util.Set;

import org.jgrapht.alg.NeighborIndex;

import edu.cmu.vlis.datamining.core.Edge;
import edu.cmu.vlis.datamining.core.Feature;
import edu.cmu.vlis.datamining.core.IFeatureCalculator;
import edu.cmu.vlis.datamining.core.Vertex;

public class CommonNeighbors implements IFeatureCalculator{

    private NeighborIndex<Vertex, Edge> nIndex;
    private int featureId;

    public CommonNeighbors(NeighborIndex<Vertex, Edge> neighborIndex) {
        this.nIndex = neighborIndex;
        this.featureId = 1;
    }

    public Feature compute(Vertex a, Vertex b) {

        Set<Vertex> neighborsA = new HashSet<Vertex>(this.nIndex.neighborsOf(a));
        Set<Vertex> neighborsB = this.nIndex.neighborsOf(b);

        neighborsA.retainAll(neighborsB);
        
        return new Feature(this.featureId,(float)neighborsA.size());
    }
    
    
}
